<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const Tool = {
        max(key) {
          return this.data.sort((a, b) => b[key] - a[key])[0];
        },
      };

      class Lesson {
        constructor(lessons) {
          this.lessons = lessons;
        }
        get data() {
          return this.lessons;
        }
      }
      // 相当于把max 方法添加到了  Lessn.prototype的原型上
      Object.assign(Lesson.prototype, Tool);
      console.dir(Lesson);
      const data = [
        { name: 'js', price: 100 },
        { name: 'mysql', price: 212 },
        { name: 'vue.js', price: 98 },
      ];
      let hd = new Lesson(data);
      console.log(hd.max('price'));
    </script>
  </body>
</html>
